//
//  Singleton.h
//  DoIT
//
//  Created by 葛欣 on 14/11/22.
//  Copyright (c) 2014年 gex. All rights reserved.
//

// .h
#define singleton_interface(className) + (instancetype)shared##className;

// .m
#define singleton_implementation(className) \
static className *_instace; \
\
+ (id)allocWithZone:(struct _NSZone *)zone \
{ \
    static dispatch_once_t onceToken; \
    dispatch_once(&onceToken, ^{ \
        _instace = [super allocWithZone:zone]; \
    }); \
    \
    return _instace; \
} \
\
+ (instancetype)shared##className \
{ \
    if (_instace == nil) { \
        _instace = [[className alloc] init]; \
    } \
    \
    return _instace; \
}